﻿namespace Resharper.Abstractions.CodeDom
{
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi;
  using Resharper.Abstractions.CodeDom.TypeMembers.Fields.Constants;

  /// <summary>Defines the <see cref="ConstantExtensions"/> class.</summary>
  internal static class AccessRightsHelper
  {
    #region Public Methods

    /// <summary>Gets the containing function.</summary>
    /// <param name="accessRightsOwner">The access rights owner.</param>
    /// <returns>Returns the containing function.</returns>
    public static AccessRights GetAccessRights([CanBeNull] IAccessRightsOwner accessRightsOwner)
    {
      if (accessRightsOwner == null)
      {
        return AccessRights.None;
      }

      switch (accessRightsOwner.GetAccessRights())
      {
        case JetBrains.ReSharper.Psi.AccessRights.PUBLIC:
          return AccessRights.Public;
        case JetBrains.ReSharper.Psi.AccessRights.INTERNAL:
          return AccessRights.Internal;
        case JetBrains.ReSharper.Psi.AccessRights.PROTECTED:
          return AccessRights.Protected;
        case JetBrains.ReSharper.Psi.AccessRights.PROTECTED_OR_INTERNAL:
          return AccessRights.Protected;
        case JetBrains.ReSharper.Psi.AccessRights.PROTECTED_AND_INTERNAL:
          return AccessRights.ProtectedInternal;
        case JetBrains.ReSharper.Psi.AccessRights.PRIVATE:
          return AccessRights.Private;
      }

      return AccessRights.None;
    }

    #endregion
  }
}